package com.example.a0510spinner0511listview;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;

public class basicListView extends AppCompatActivity {
    ListView listView;

    private String[] data = {"Apple", "Banana", "Cherry", "Grape", "Mango", "Orange", "Pear",
            "Pineapple", "Strawberry", "Watermelon", "Apple", "Banana", "Cherry", "Grape", "Mango",
            "Orange", "Pear", "Pineapple", "Strawberry", "Watermelon"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_basic_list_view);

        // 建立一个ArrayAdapter对象，类型为String，将数据与适配器绑定在一起
        ArrayAdapter<String> adapter = new ArrayAdapter<>(
                basicListView.this,
                android.R.layout.simple_list_item_1,
                data
        );
        listView = (ListView) findViewById(R.id.list_view);
        // 通过listView将数据显示出来
        listView.setAdapter(adapter);
    }
}